﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ChinaGS.Lian.ModuleRemoting;

public partial class pay_express_fill_utilities : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SysCommon.checkUserLogin();
        if (!IsPostBack)
        {
            String Charge = Request["HidCharge"];
            String CusAddress = Request["HidCusAddress"];
            String CusName = Request["HidCusName"];
            String CusNo = Request["HidCusNo"];
            String DueMoney = Request["HidDueMoney"];
            String LastCheckDate = Request["HidLastCheckDate"];
            String ReceiPay = Request["HidReceiPay"];

            if (Request["HidCharge"] != null)
            {
                LabCharge.Text = Charge;
                LabCusAddress.Text = CusAddress;
                LabCusName.Text = CusName;
                LabCusNo.Text = CusNo;
                LabDueMoney.Text = DueMoney;
                LabLastCheckDate.Text = LastCheckDate;
                LabReceiPay.Text = ReceiPay;

                HidCharge.Value = Charge;
                HidCusAddress.Value = CusAddress;
                HidCusName.Value = CusName;
                HidCusNo.Value = CusNo;
                HidDueMoney.Value = DueMoney;
                HidLastCheckDate.Value = LastCheckDate;
                HidReceiPay.Value = ReceiPay;

                PanPay.Visible = true;
            }else{
                PanPay.Visible = false;
                this.LabMessage.Text = "操作失败，请重试！";
            }
        }
    }
    protected void NextStep_Click(object sender, EventArgs e)
    {

        //充值前操作            
        int user_paid_id = DataBaseOperate_SQLServer.execPPaidAtonce(Session["user_id"].ToString(), "6".ToString(), HidCusNo.Value, 
                TexPayMoney.Text, TexPayMoney.Text, "0".ToString(), "0".ToString(), "0".ToString(), System.DateTime.Now.ToString(), "none".ToString());

        if (user_paid_id < 0)
        {
            LabMessage.Text = "操作失败！原因是：" + RemotingClass.alertExecErroeResult(user_paid_id).ToString() + "，请重试";
            PanPay.Visible = false;
        }
        else {
            UtilitiesPackage up = RemotingClass.utilitiesPayMoney(HidCusNo.Value, System.Convert.ToDouble(HidCharge.Value), System.Convert.ToDouble(TexPayMoney.Text));

            //测试使用
            /*UtilitiesPackage up = new UtilitiesPackage();
            up.Status = true;
            up.SerialNo = "1234567890";
            up.Message = "success";
            up.StatusNo = "00";

            up.CusNo = HidCusNo.Value;
            up.CusName = "denveryee";
            up.CusAddress = "qd";
            up.Charge = 10;
            up.RealPay = 0;
            up.ReceiPay = 100;
            up.LastCheckDate = DateTime.Now.ToString("yyyy年MM月dd日");
            up.PayDate = DateTime.Now.ToString("yyyy年MM月dd日");
            up.DueMoney = 10;*/

            if (up.Status)
            {
                //充值成功操作                
                DataBaseOperate_SQLServer.execPPaidSetStatus(user_paid_id.ToString(), up.SerialNo,
                    up.CusNo, up.Message, "1".ToString(), SysCommon.getClientIP(), "0".ToString());

                Response.Redirect("paysuccess_utilities.aspx?"
                                                + "HidCharge=" + up.Charge.ToString()
                                                + "&HidCusAddress=" + up.CusAddress
                                                + "&HidCusName=" + up.CusName
                                                + "&HidCusNo=" + up.CusNo
                                                + "&HidDueMoney=" + up.DueMoney.ToString()
                                                + "&HidLastCheckDate=" + up.LastCheckDate
                                                + "&HidReceiPay=" + up.ReceiPay.ToString()
                                                + "&HidRealPay=" + up.RealPay.ToString());
            }
            else
            {
                //充值失败操作                
                DataBaseOperate_SQLServer.execPPaidSetStatus(user_paid_id.ToString(), up.SerialNo,
                    up.CusNo, up.Message, "2".ToString(), SysCommon.getClientIP(), "0".ToString());

                LabMessage.Text = "操作失败！原因是：" + up.Message + "，请稍后重试";
                PanPay.Visible = false;
            }
        
        }
        
    }
}

